package main

import (
	"fmt"
	"time"
)

func main() {
	// 限制每200毫秒执行一次
	requests := make(chan int, 5)
	for i := 0; i < 5; i++ {
		requests <- i
	}
	close(requests)
	limier := time.Tick(200 * time.Millisecond)
	for req := range requests {
		<-limier
		fmt.Println(req, "time,", time.Now())
	}
	// burstylimiter有三个容量，每300毫秒执行一次
	burstylimiter := make(chan time.Time, 3)
	for i := 0; i < 3; i++ {
		burstylimiter <- time.Now()
	}
	go func() {
		for t := range time.Tick(300 * time.Millisecond) {
			burstylimiter <- t
		}
	}()

	request1 := make(chan int, 5)
	for i := 0; i < 5; i++ {
		request1 <- i
	}
	close(request1)
	for ele := range request1 {
		<-burstylimiter
		fmt.Println(ele, "time,", time.Now())
	}
}
